package com.hx.er.action.admin.settings;

import org.springframework.beans.factory.annotation.Autowired;

import com.hx.er.action.base.ErAdminAction;
import com.hx.er.bean.detail.CityDetailBean;
import com.hx.er.service.admin.IAdminSettingsService;

/**
 * @author HX
 * 
 */
public class AdminCityDeleteAction extends ErAdminAction {
	// 序列化ID
	private static final long serialVersionUID = -1127474451530316813L;

	private long cityId;
	private CityDetailBean cityDetailBean;

	@Autowired
	private IAdminSettingsService adminSettingsService;

	public String init() {
		this.initPage();
		return SUCCESS;
	}

	public String delete() {
		this.cityDetailBean.setCityId(this.cityId);
		this.cityDetailBean.setUpdateUserId(super.getUserInfoLogin().getUserId());

		int count = this.adminSettingsService.deleteCity(this.cityDetailBean);

		if (count == 0) {
			this.initPage();
			this.addActionError(super.getText(DELETE_FAILURE_MSG));
			return INPUT;
		} else {
			// 缓存中删除该餐厅
			this.addActionMessage(super.getText(DELETE_SUCCESS_MSG));
			return SUCCESS;
		}
	}

	private void initPage() {
		// 查询餐馆信息
		this.cityDetailBean = this.adminSettingsService.getCityDetailById(this.cityId);
	}

	public long getCityId() {
		return cityId;
	}

	public void setCityId(long cityId) {
		this.cityId = cityId;
	}

	public CityDetailBean getCityDetailBean() {
		return cityDetailBean;
	}

	public void setCityDetailBean(CityDetailBean cityDetailBean) {
		this.cityDetailBean = cityDetailBean;
	}

}
